/*
 * Created on 2005-3-22
 *
 * Copyright: Bluejay Networks Inc. 2005
 *
 * This software is the proprietary information of Bluejay Networks Inc. 
 * 
 * Use is subject to license terms.
 * 
 */
package com.ims.iaa.swf.button.action;

import com.ims.iaa.swf.ByteArrayUtil;
import com.ims.iaa.swf.SwfObject;

/**
 * @author ShengMengBai
 *
 */
public abstract class BaseAction implements SwfObject{
    public static final int ACTION_GETURL1 = (byte)0x83;
    public static final int PUSHPARA = (byte)0x96;
    public static final int GETVARIA = (byte)0x1C;
    public static final int DATATYPESTRING = (byte)0x00;
    public static final int ACTION_GETURL2 = (byte)0x9A;
//ActionCode		code = UI8				An action code as specified below      
//Length			If code >= 0x80 UI16	The number of bytes (after this) in the ACTIONRECORD      
    public static BaseAction parse(byte[] bytData, int iOffset){
	    //System.out.println("ActionCode " + iActionCode + " Position: " + iOffset);
	    while(bytData[iOffset] != 0){
		    int iActionCode = bytData[iOffset];
		    if(iActionCode == GetURLAction.code){
		        GetURLAction action = new GetURLAction(bytData, iOffset);
			    if(action.parse()){
			        return action;
			    }
		    }else if(iActionCode == GetURLAction2.code){
		        GetURLAction2 action = new GetURLAction2(bytData, iOffset);
			    if(action.parse()){
			        return action;
			    }
			    return null;
		    }else{
	            iOffset++;
		        if(iActionCode < 0){
		            int iLen = ByteArrayUtil.toShort(bytData, iOffset);
		            iOffset += iLen + 2;
		        }
		    }
	    }
        return null;
    }
}
